import 'package:flutter/material.dart';

// 定义有状态组件
// 快捷键：fstfull，得安装插件：Flutter Widget Snippets
class HomePage10_3 extends StatefulWidget {
  const HomePage10_3({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage10_3> {
  // 状态变量
  int count = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('ListView组件', style: TextStyle(color: Colors.white)),
        backgroundColor: Colors.blue,
      ),

      body: ListView.separated(
        // 构造每一项的函数
        itemBuilder: (BuildContext context, int index) {
          return Container(
            height: 100,
            color: Colors.red[90],
            child: Container(
              padding: const EdgeInsets.all(10),
              child: Row(
                children: [
                  Image.network(
                    'https://yanxuan-item.nosdn.127.net/e529b6ab111ade9da9314867f98d360f.png',
                    width: 90,
                  ),
                  const Expanded(
                    child: Text(
                      '海尔（Haier）波轮洗衣机全自动家用 10公斤大容量 直驱变频 一级能效 高效精华洗 以旧换新EB100B37Mate5',
                      maxLines: 2,
                      overflow: TextOverflow.ellipsis,
                    ),
                  ),
                  const Padding(
                    padding: EdgeInsets.only(left: 10),
                    child: Icon(Icons.access_time_filled),
                  ),
                ],
              ),
            ),
          );
        },
        // 构造分割线的函数
        separatorBuilder: (context, index) {
          return Container(
            height: 1,
            color: Colors.grey,
            // 横向两侧间距
            margin: EdgeInsets.symmetric(horizontal: 20),
          );
        },
        // 列表的长度
        itemCount: 10,
      ),
    );
  }
}
